class Cookie {
  constructor() {

  }

  setCookie(cname,cvalue,exMinute){
    let d = new Date();
    d.setTime(d.getTime()+(exMinute*60*1000));
    let expires = "expires="+ d['toGMTString']();
    document.cookie = cname+"="+cvalue+"; "+expires;
  }

  getCookie(cname){
    let name = cname + "=";
    let ca = document.cookie.split(';');
    for(let i=0; i<ca.length; i++) {
      let c = ca[i].trim();
      if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
    }
    return "";
  }

  // function checkCookie(){
  //   var user=getCookie("username");
  //   if (user!=""){
  //     alert("欢迎 " + user + " 再次访问");
  //   }
  //   else {
  //     user = prompt("请输入你的名字:","");
  //     if (user!="" && user!=null){
  //       setCookie("username",user,30);
  //     }
  //   }
  // }
}
const cookie = new Cookie();
export default cookie;
